#!/bin/sh -ev

gitdo() {
    /usr/bin/expect <<EOF
spawn $*
set timeout -1
expect {
"Username" { send "$gituser\r"; exp_continue; }
"Password" { send "$gitpass\r"; exp_continue; }
eof { }
}
EOF
}

[ -n "$gituser" ] || read -p "gituser: " gituser
[ -n "$gitpass" ] || read -s -p "gitpass: " gitpass
commit_count=`git log | grep '^commit ' | wc -l`
reset_count=$((commit_count-1))
rm * -rf
git checkout .
git reset --hard HEAD~$reset_count
gitdo git pull
